﻿using System;
using System.Windows;
using System.Windows.Navigation;
using Croxweb.Leuphana.ViewModels;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

namespace Croxweb.Leuphana.Pages
{
    public partial class PersonPage : PhoneApplicationPage
    {
        private PersonDetailViewModel viewModel;

        public PersonPage()
        {
            InitializeComponent();

            DataContext = viewModel = new PersonDetailViewModel(App.MyStudyService);
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            String id;
            NavigationContext.QueryString.TryGetValue("id", out id);

            viewModel.LoadPerson(int.Parse(id));
        }

        private void SendMail_Click(object sender, RoutedEventArgs e)
        {
            EmailComposeTask task = new EmailComposeTask();
            task.To = viewModel.EmailAddress;

            task.Show();
        }

        private void CallPhone_Click(object sender, RoutedEventArgs e)
        {
            PhoneCallTask task = new PhoneCallTask();
            task.PhoneNumber = viewModel.Phone;

            task.Show();
        }

        private void CallMobile_Click(object sender, RoutedEventArgs e)
        {
            PhoneCallTask task = new PhoneCallTask();
            task.PhoneNumber = viewModel.Mobile;

            task.Show();
        }

        private void ShowWebsite_Click(object sender, RoutedEventArgs e)
        {
            WebBrowserTask task = new WebBrowserTask();
            task.URL = viewModel.Website;

            task.Show();
        }
    }
}